library(readxl)
library(tidyverse)
df <- read_xlsx("GET THE DATA FROM GTD: WE CANNOT REPOST")



df <- df |> filter(country == 228,
                   iyear <= 2012) |> 
  mutate(attacktype1_txt = factor(attacktype1_txt),
         targtype1_txt = factor(targtype1_txt),
         weaptype1_txt = factor(weaptype1_txt)
         )

df |> skimr::skim()


table(df$suicide, df$iyear) # not actually that much experience; 8 total attacks in the 2000s including the USS cole attack, 7 each in 2010 and 2011

df_bomb <- df |> filter(attacktype1_txt == "Bombing/Explosion") 

# GTD has 314 entries for Yemen between 1991 and 2010

table(df$iyear, df$nkill) # Zero mass casualty attacks before 2010; largest excluding Cole was 16 in 2009

table(df_bomb$iyear, df_bomb$nkill)

table(df_bomb$iyear, df_bomb$nwound)

df |> filter(city == "Sanaa") |>
  mutate(date = lubridate::make_date(iyear, imonth,iday)) |> 
  ggplot() + geom_point(aes(x = date, y = nkill)) + 
  annotate("label", x = as.Date("2011-06-03"), y = 7.2, label = "Palace Bombing", angle = 90, vjust = -.6, hjust = -.4, color = "red") + 
  annotate("label", x = as.Date("2008-09-17"), y = 13, label = "US Embassy Attack",  angle = 90, vjust = -.6, hjust = -.4) +
  annotate("label", x = as.Date("2012-05-21"), y = 90, label = "Suicide Bombing", angle = 90, vjust = -.6, color = "orange") +
  annotate("label", x = as.Date("2012-07-11"), y = 20, label = "Police Academy Attack", angle = 90, vjust = 1.7, color = "darkgreen") +
  geom_vline(xintercept = as.Date("2011-06-03"), linetype = "dashed", color = "red") +
  geom_vline(xintercept = as.Date("2012-05-21"), linetype = "dashed", color = "orange") +
  geom_vline(xintercept = as.Date("2012-07-11"), linetype = "dashed", color = "darkgreen") +
  
  labs(title = "Terrorist attacks in Sana'a, 1990 - 2012",
       x = "Year",
       y = "Fatalities") + xlim(c(1989,2014)) + scale_x_date() + theme_minimal()
  


df |> filter(city == "Sanaa" & nkill > 5) |> View()

df |> filter(city == "Jaar") |>
  mutate(date = lubridate::make_date(iyear, imonth,iday)) |> 
  ggplot() + geom_point(aes(x = date, y = nkill)) + 
  annotate("label", x = as.Date("2011-03-28"), y = 90, label = "Factory Explosion", angle = 90, vjust = -.6, hjust = -.4, color = "red") +
  geom_vline(xintercept = as.Date("2011-03-28"), linetype = "dashed", color = "red") +
  labs(title = "Terrorist attacks in Ja'ar, 1990 - 2012",
       x = "Year",
       y = "Fatalities") + 
       scale_x_date() + theme_minimal() 


df |> filter(city == "Al-Mukalla") |>
  mutate(date = lubridate::make_date(iyear, imonth,iday)) |> 
  ggplot() + geom_point(aes(x = date, y = nkill)) + 
  annotate("label", x = as.Date("2011-02-26"), y = 5, label = "Palace Bombing", angle = 90, vjust = -.6, hjust = 2, color = "red") + 
  geom_vline(xintercept = as.Date("2011-02-26"), linetype = "dashed", color = "red") +
  labs(title = "Terrorist attacks in Al-Mukalla, 1990 - 2012",
       x = "Year",
       y = "Fatalities") + 
  scale_x_date() + theme_minimal() 



df |> filter(city == "Sanaa" & nkill > 5) |> View()
